package pcb.models.vo 
{
	import flash.events.EventDispatcher;
	import pcb.models.events.ModelEvent;
	
	/**
	 * 
	 * @author Fintan Boyle
	 */
	public class Slide extends EventDispatcher implements ISlide, IPage 
	{
		public static const INTERACTIVE:String = "try";
		public static const ACTIVITY_CARD:String = "activity_card";
		public static const DIDACTIC:String = "didactic";
		
		private var _id:String;
		private var _containerId:String;
		private var _title:String;
		private var _type:String;
		private var _pageType:String;
		private var _hasVO:Boolean;
		
		/**
		 * boolean to reflect the load status of slide assets such as audio
		 */
		private var _loaded:Boolean;
		
		/**
		 * corresponds to AssetModel.getAssetbyId()
		 * TODO may not need this if library components have direct access to AssetModel
		 */
		private var _assets:Array;
		private var _interactions:Array;
		
		private var vo:NarrativeVo;
		
		/**
		 * TODO - maybe labels can be treated at lesson level instead??
		 */
		//public var labels:XMLList;
		
		public function Slide(id:String="",title:String="",type:String=DIDACTIC,loaded:Boolean=false) 
		{
			_id = id;
			_title = title;
			_type = type;
			_containerId = "";
			this.setLoaded(loaded);
			//_pageType = PageTypes.SLIDE;
			
			_assets = new Array();
			_interactions = new Array();
		}
		
		/* INTERFACE pcb.models.vo.IPage */
		public function setVO(in_vo:NarrativeVo):void 
		{
			vo = in_vo;
			
			_hasVO = (vo != null)?true:false;
		}
		
		public function getVO():NarrativeVo 
		{
			return vo;
		}
		
		public function hasVO():Boolean
		{
			if (!_hasVO) return false;
			
			return _hasVO;
		}
		
		public function getId():String
		{
			return _id
		}
		
		public function setId(id:String):void
		{
			_id = id;
		}
		
		public function getTitle():String
		{
			return _title;
		}
		
		public function setTitle(title:String):void
		{
			_title = title;
		}
		
		public function isLoaded():Boolean
		{
			return _loaded;
		}
		
		public function setLoaded(boo:Boolean):void
		{
			_loaded = boo;
			
			if (_loaded) {
				
				
				
				var e:ModelEvent = new ModelEvent(ModelEvent.LOADED);
				e.id = this.getId();
				this.dispatchEvent(e);
			}
			
		}
		
		public function setPageType(type:String):void 
		{
			_pageType = type;
		}
		
		public function getPageType():String
		{
			return _pageType;
		}
		
		/* INTERFACE pcb.models.vo.ISlide */
		
		public function getPedagogy():String
		{
			return _type;
		}
		
		public function setPedagogy(type:String):void
		{
			_type = type;
		}
		
		public function addAssetId(id:String):void {
			_assets.push(id);
		}
		
		public function ownsAsset(id:String):Boolean {
			for (var i:int = 0; i < _assets.length; i++) 
			{
				if (_assets[i] == id) {
					return true;
				}
			}
			return false;
		}
		
		public function getContainerId():String
		{
			return "learn";
		}
		
		public function setContainerId(id:String):void
		{
			_containerId = id;
		}
		
		public function addInteractions(in_interactivities:XMLList):void {			
			for each (var xInteractivity:XML in in_interactivities.children()) {
				_interactions.push(new Interaction(xInteractivity.@id, xInteractivity.@type, xInteractivity.annotation, xInteractivity.answer));				
			}			
		}
		
		public function getInteractionIDs():Array
		{
			var interActionIDs:Array = new Array();
			for each (var i:Interaction in _interactions) 
			{
				interActionIDs.push(i.id);
			}
			return interActionIDs;
		}
		
		public function getInteractionByID(id:String):Interaction
		{
			for each (var i:Interaction in _interactions) 
			{
				if (i.id == id) {
					return i;
				}
			}
			return null;
		}
	}
	
}